package com.xinggq.pay.service.config;

import com.xinggq.pay.service.interceptor.AppIdInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web MVC配置类
 * 注册拦截器
 *
 * @since 2024
 */
@Configuration
@RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer {

    private final AppIdInterceptor appIdInterceptor;
    private final AppIdValidationConfig appIdValidationConfig;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册AppId拦截器，应用于所有路径
        // 具体的路径校验逻辑由AppIdValidationConfig和AppIdInterceptor处理
        registry.addInterceptor(appIdInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/favicon.ico", "/error");
    }
}